package redis

import (
	"context"
	"enjoy-joy/common/nacos"
	user "enjoy-joy/common/proto"
	"fmt"
	"github.com/go-redis/redis/v8"
	"time"
)

var Rdb *redis.Client

func InitRedis() {
	nac := nacos.NacosConfig.Redis
	Rdb = redis.NewClient(&redis.Options{
		Addr:     nac.Addr,
		Password: nac.Password, // no password set
		DB:       nac.Db,       // use default DB
	})

	fmt.Println("redis连接成功")
}

func SendSmsSet(key string, code int) {
	Rdb.Set(context.Background(), key, code, time.Minute*10)
}

func SendSmsGet(key string) int {
	i, err := Rdb.Get(context.Background(), key).Int()
	if err != nil {
		return 0
	}
	return i
}

func ClassL(key string, item []*user.ClassList) {
	Rdb.LPush(context.Background(), key, item)
}
